public class Main {
    public static String solution(int n, int k, String s) {
        char[] arr = s.toCharArray();
        int usedK = 0;

        for (int i = 0; i < arr.length && usedK < k; i++) {
            if (arr[i] == '0') {
                // 找到这个0可以移动的最远位置
                int j = i;
                while (j > 0 && arr[j-1] == '1' && usedK < k) {
                    // 交换相邻字符
                    char temp = arr[j];
                    arr[j] = arr[j-1];
                    arr[j-1] = temp;
                    j--;
                    usedK++;
                }
            }
        }

        return new String(arr);
    }

    public static void main(String[] args) {
        System.out.println(solution(5, 2, "01010").equals("00101"));
        System.out.println(solution(7, 3, "1101001").equals("0110101"));
        System.out.println(solution(4, 1, "1001").equals("0101"));
    }
}
